// pages/detail/detail.js
//引入js文件
var myDetail = require("../../data/detail.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    product_id: null,
    isLike: true,
    indicatorDots: true, //是否显示面板指示点
    autoplay: true, //是否自动切换
    interval: 30000, //自动切换时间间隔,3s
    duration: 10000, //  滑动动画时长1s
    imgUrls: [],
    detailImg: [],
    flex: false,
    productNavtab: 0,
    instructions:[],
    scrollTop: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      product_id: options.pid,
      imgUrls: myDetail.product_images(),
      detailImg: myDetail.detail_image(),
      instructions: myDetail.instructions(),
    });
  },

  //预览图片
  previewImage: function (e) {
    var current = e.target.dataset.src;
    wx.previewImage({
      current: current, // 当前显示图片的http链接  
      urls: this.data.imgUrls // 需要预览的图片http链接列表  
    })
  },

  // 滚动监听  
  scroll: function (e) {
    var that = this;
    var top = e.detail.scrollTop;
    console.log(top);
    wx.getSystemInfo({
      success: function (res) {
        var wh = res.windowHeight;
        console.log(wh);
        var flag = false;
      },
    })
    that.setData({
      scrollTop: e.detail.scrollTop
    })
  },

  //切换tab
  switchTab: function (e) {
    var that = this;
    that.setData({
      productNavtab: e.currentTarget.dataset.pdx
    });
  },

  // 立即租用
  immeRent() {
    wx.showToast({
      title: '租用成功',
      icon: 'success',
      duration: 2000
    });
  },
})